<script>
/*
 * Copyright (c) 2012-2013 RockStor, Inc. <http://rockstor.com>
 * This file is part of RockStor.
 *
 * RockStor is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * RockStor is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
</script>

<div class="messages"></div>
<!-- page heading -->

{{#if diskSmartNotAvailable}}
<div class="alert alert-danger">
  <h4>S.M.A.R.T support is not available for this disk ({{diskName}}).<br>
	Please see the S.M.A.R.T column entry for this disk on the Storage - Disks
	page; custom options may be required.</h4>
</div>
{{else if diskSmartNotEnabled}}
<div class="alert alert-warning">
  <h4>Warning! S.M.A.R.T support is not enabled for this disk ({{diskName}}).
	<br>If available it can be enabled in the S.M.A.R.T column entry for this disk
	on the Storage - Disks page.</h4>
</div>
{{else}}
<div class="pull-right">
  <button id="smartinfo" class="btn btn-primary pull-right" title="Refresh for latest information"><i class="glyphicon glyphicon-refresh "></i>Refresh</button>
</div>
<span class="h2">S.M.A.R.T details for <strong>{{diskName}}</strong></span>
{{/if}}

<ul class="nav nav-tabs">
  <li class="active"><a href="#smartidentity" data-toggle="tab">Identity</a></li>
  <li><a href="#smartattributes" data-toggle="tab">Attributes</a></li>
  <li><a href="#smartcapabilities" data-toggle="tab">Capabilities</a></li>
  <li><a href="#smarterrorlogs" data-toggle="tab">Error Logs</a></li>
  <li><a href="#smarttestlogs" data-toggle="tab">Self-Test Logs</a></li>
  <li><a href="#smarttests" data-toggle="tab">Perform Tests</a></li>
</ul>

<div class="css-panes">

  <div id="smartidentity">
    <div class="row">
      {{#if identity}}
      <table id="smartidentity-table" class="table table-condensed table-bordered table-hover table-striped tablesorter" summary="List of S.M.A.R.T identity attributes">
	<thead>
	  <tr>
	    <th>Attribute</th>
	    <th>Value</th>
	  </tr>
	</thead>
	<tbody>
	  <tr>
	    <td><strong>Model Family</strong></td>
	    <td>{{identity.model_family}}</td>
	  </tr>
	  <tr>
	    <td><strong>Device Model</strong></td>
	    <td>{{identity.device_model}}</td>
	  </tr>
	  <tr>
	    <td><strong>Serial Number</strong></td>
	    <td>{{identity.serial_number}}</td>
	  </tr>
	  <tr>
	    <td><strong>World Wide Name</strong></td>
	    <td>{{identity.world_wide_name}}</td>
	  </tr>
	  <tr>
	    <td><strong>Firmware Version</strong></td>
	    <td>{{identity.firmware_version}}</td>
	  </tr>
	  <tr>
	    <td><strong>Capacity</strong></td>
	    <td>{{identity.capacity}}</td>
	  </tr>
	  <tr>
	    <td><strong>Sector Size</strong></td>
	    <td>{{identity.sector_size}}</td>
	  </tr>
	  <tr>
	    <td><strong>Rotation Rate</strong></td>
	    <td>{{identity.rotation_rate}}</td>
	  </tr>
	  <tr>
	    <td><strong>In Smartctl Database</strong></td>
	    <td>{{identity.in_smartdb}}</td>
	  </tr>
	  <tr>
	    <td><strong>ATA Version</strong></td>
	    <td>{{identity.ata_version}}</td>
	  </tr>
	  <tr>
	    <td><strong>SATA Version</strong></td>
	    <td>{{identity.sata_version}}</td>
	  </tr>
	  <tr>
	    <td><strong>Scanned on</strong></td>
	    <td>{{identity.scanned_on}}</td>
	  </tr>
	  <tr>
	    <td><strong>SMART Supported</strong></td>
	    <td>{{identity.supported}}</td>
	  </tr>
	  <tr>
	    <td><strong>SMART Enabled</strong></td>
	    <td>{{identity.enabled}}</td>
	  </tr>
	  <tr>
	    <td><strong>Smartctl Version</strong></td>
	    <td>{{identity.version}}</td>
	  </tr>
	  <tr>
	    <td><strong>Overall Health Self-Assessment Test</strong></td>
	    <td>{{identity.assessment}}</td>
	  </tr>
	</tbody>
      </table>
      {{/if}}
    </div>
  </div>

  <div id="smartattributes">
    <div class="row">
      <table id="smartattributes-table" class="table table-condensed table-bordered table-hover table-striped tablesorter" summary="List of S.M.A.R.T attributes">
	<thead>
	  <tr>
	    <th>Name</th>
	    <th>Failed</th>
	    <th>Norm-ed Value</th>
	    <th>Worst</th>
	    <th>Threshold</th>
	    <th>Raw Value</th>
	    <th>Type</th>
	    <th>Updated</th>
	    <th>Flag</th>
      <th>Id</th>
	  </tr>
	</thead>
	<tbody>
	  {{#each attributes as |attribute|}}
	  <tr>
      <td><strong>{{attribute.name}}</strong></td>
	    <td>{{attribute.failed}}</td>
	    <td>{{attribute.normed_value}}</td>
	    <td>{{attribute.worst}}</td>
	    <td>{{attribute.threshold}}</td>
	    <td><strong>{{attribute.raw_value}}</strong></td>
	    <td>{{attribute.atype}}</td>
	    <td>{{attribute.updated}}</td>
	    <td>{{attribute.flag}}</td>
      <td>{{attribute.aid}}</td>
	  </tr>
	  {{else}}
	  <h3>No S.M.A.R.T Attributes found (ATA/SATA only)</h3>
	  {{/each}}
	</tbody>
      </table>
    </div>
  </div>

  <div id="smartcapabilities">
    <div class="row">
      <table id="smartcapabilites-table" class="table table-condensed table-bordered table-hover table-striped tablesorter" summary="Table of S.M.A.R.T capabilities">
	<thead>
	  <tr>
	    <th>Name</th>
	    <th>Flag</th>
	    <th>Capabilities</th>
	  </tr>
	</thead>
	<tbody>
	  {{#each capabilities as |capability|}}
	  <tr>
	    <td><strong>{{capability.name}}</strong></td>
	    <td>{{capability.flag}}</td>
	    <td>{{capability.capabilities}}</td>
	  </tr>
	  {{else}}
	  <h3>No S.M.A.R.T Capabilities found (ATA/SATA only)</h3>
	  {{/each}}
	</tbody>
      </table>
    </div>
  </div>

  <div id="smarterrorlogs">
    <div class="row">
      {{#if errorLogSummaryNull}}
      {{#isAboveMinLength 4 errorlog}}
      <h3>No error summary available, please see the raw log below.</h3>
      {{else}}
      <h3>There are no errors.</h3>
      {{/isAboveMinLength}}
      {{else}}
      <p>{{errorlogZero}}</p>
      <p>{{errorlogOne}}</p>
      <table id="smarterrorlogsummary-table"
	     class="table table-condensed table-bordered table-hover table-striped tablesorter"
	     summary="Table of S.M.A.R.T error log summary">
	<thead>
	  <tr>
	    <th>Error #</th>
	    <th>Lifetime hours</th>
	    <th>State</th>
	    <th>Type</th>
	    <th>Details</th>
	  </tr>
	</thead>
	<tbody>
	  {{#each errorlogsummary as |summary|}}
	  <tr>
	    <td>{{summary.error_num}}</td>
	    <td>{{summary.lifetime_hours}}</td>
	    <td>{{summary.state}}</td>
	    <td>{{summary.etype}}</td>
	    <td>{{summary.details}}</td>
	  </tr>
	  {{/each}}
	</tbody>
      </table>
      {{/if}}
      {{#isAboveMinLength 4 errorlog}}
      <h3>Raw S.M.A.R.T error log</h3>
      <pre>
	{{#each errorlog as |log|}}
	{{log.line}}
	{{/each}}
      </pre>
      {{/isAboveMinLength}}
    </div>
  </div>

  <div id="smarttestlogs">
    <div class="row">
      {{#if testLogNull}}
      <h3>There are no Self-Test logs.</h3>
      {{else}}
      <p>Number of entries in the log: {{testlogLength}}</p>
      <table id="smarttestlog-table" class="table table-condenced table-bordered table-hover table-striped tablesorter" summary="Table of S.M.A.R.T test log">
	<thead>
	  <tr>
	    <th>Test #</th>
	    <th>Type</th>
	    <th>Status</th>
	    <th>% Completed</th>
	    <th>Lifetime hours</th>
	    <th>LBA of the first error</th>
	  </tr>
	</thead>
	<tbody>
	  {{#each testlog as |log|}}
	  <tr>
	    <td>{{log.test_num}}</td>
	    <td>{{log.description}}</td>
	    <td>{{log.status}}</td>
	    <td>{{log.pct_completed}}</td>
	    <td>{{log.lifetime_hours}}</td>
	    <td>{{log.lba_of_first_error}}</td>
	  </tr>
	  {{/each}}
	</tbody>
      </table>
      <pre>
	{{#each testlogdetail as |detail|}}
	{{detail.line}}
	{{/each}}
      </pre>
      {{/if}}
    </div>
  </div>

  <div id="smarttests">
    <div class="row">
      {{#if smartNotAvailableEnabled}}
      <div class="alert alert-danger">
	<h4>Tests cannot be run because S.M.A.R.T support is either unavailable or
		disabled.</h4>
      </div>
      {{else}}
      <p>
	Self-tests are built-in tests within the drive designed to recognize
	drive fault conditions. All self-tests are safe to user data. The tests
	can be performed during normal system operation, but will take longer
	to complete if the drive is not idle.
      </p>
      <div class="col-md-8">
	<label class="control-label"></label>
	<div class="form-box">
	  <form  name="run-test-form" id="run-test-form">
	    <div class="messages"></div>
	    <div class="form-group">
	      {{#if notRunningTest}}
	      <label class="control-label" for="test_type">Test Type </label>
	      <div class="">
		<select id="test_name" name="test_name" title="select the test you want to run">
		  {{#each tests}}
		  <option value="{{@key}}">{{@key}}    (Estimated duration: {{this}})</option>
		  {{/each}}
		</select>
	      </div>
	    </div>
	    <div class="form-group">
	      <div class="">
		<button id="test-start" class="btn btn-primary" title="Start the test">Start Test</button>
	      </div>
	    </div>
	    {{else}}
	    <div class="form-group">
	      <h4>{{running_test}}</h4>
	      <p>Wait until this test finishes to start a new one. Refresh for an update.</p>
	    </div>
	    {{/if}}
	  </form>
	</div>
      </div>
      {{/if}}
    </div>
  </div>
</div>
